const util = require('../../utils/util.js');
const mapNames = {
  'childButler.childButlerAdd': '育儿管家',
  'childCare.childCareAdd': '幼儿照护',
  'childCompanion.childCompanionAdd': '儿童心里陪伴师',
  'businessAndGovernmentServices.businessAndGovernmentServicesAdd': '政企服务',
  'dailyClean.dailyCleanAdd': '日常保洁',
  'domesticHousekeeper.domesticHousekeeperAdd': '家庭事务管家',
  'electricalClean.electricalCleanAdd': '家电清洗',
  'electricalRepair.electricalRepairAdd': '家电维修',
  'floorWaxing.floorWaxingAdd': '地板打蜡',
  'headButler.headButlerAdd': '首席管家',
  'homeEducationHousekeeper.homeEducationHousekeeperAdd': '家庭教育管家',
  'householdCare.householdCareAdd': '家务料理',
  'internationalEducationManager.internationalEducationManagerAdd': '国际教育管家',
  'japaneseClean.japaneseCleanAdd': '日式保洁',
  'leatherGoodsMaintenance.leatherGoodsMaintenanceAdd': '皮具保养',
  'obstetricNursing.obstetricNursingAdd': '母婴护理',
  'olderHomeCare.olderHomeCareAdd': '居家养老',
  'petDomestication.petDomesticationAdd': '宠物驯养',
  'petFeed.petFeedAdd': '宠物喂养',
  'petMedicine.petMedicineAdd': '宠物医疗',
  'petWalk.petWalkAdd': '宠物遛养',
  'pipeDredging.pipeDredgingAdd': '管道疏通',
  'privateChef.privateChefAdd': '家宴私厨',
  'sortingStorage.sortingStorageAdd': '整理收纳',
  'unlockTheDoor.unlockTheDoorAdd': '上门开锁',
  'waterElectricityRepair.waterElectricityRepairAdd': '水电维修',
}
function getName(name) {
  let newStr
  if (name.length === 2) {
    newStr = name.substr(0, 1) + '*'
  } else if (name.length > 2) {
    let char = ''
    for (let i = 0, len = name.length - 2; i < len; i++) {
      char += '*'
    }
    newStr = name.substr(0, 1) + char + name.substr(-1, 1)
  } else {
    newStr = name
  }
  return newStr
}
Page({
  data: {
    logs: [],
    list: [],
    loading:0,//0,1,2
  },
  onShow() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    };
    this.getInit();
  },
  getInit() {
    this.setData({
      loading:0
    })
    util.https('job/JobsQry', {
      "name": "",
      "phone": "",
      "state": "",
      "userId": ""
    }, (res) => {
      console.log(res)
      if (res.childCareBos) {
        res.childCareBos.forEach(item => {
          // if (item.jobCode) {
            // item.CodeToName = mapNames[item.jobCode]
            item.nametm = item.name ? getName(item.name) : ''
          // }
        })
        this.setData({
          list: res.childCareBos,
          loading:1
        });
        console.log(res.childCareBos)
      }

    }, (res) => {
      console.log(res)
      wx.showModal({
        title: '温馨提示',
        content: res.errorMsg,
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
    })
  },
  handleItem(e) {
    const data = e.currentTarget.dataset
    wx.setStorageSync('gongdan', data.item);
    wx.navigateGo({ url: '/page1/gongdan/index?itemID='+ data.item.id})
  },
  onPullDownRefresh() {
    console.log('onPullDownRefresh')
    // wx.stopPullDownRefresh()
  },
  onReachBottom() {
    console.log('onReachBottom')
    // wx.stopPullDownRefresh()
  },

  onLoad() {
    console.log('xinpinshow')
  },
  onShareAppMessage() {

  },
  // onShareTimeline(){

  // }
})
